import { Component } from '@angular/core';
import { Student } from './model/student';
import { StudentService } from './service/student.service';
import { StudentVo } from './vo/studentvo';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  title='angular';
  //变量类型声明
testvalue:String;
numbervalue:Number;
student:Student;
s1:Array<Student>;

studentvo:StudentVo;


constructor(private studentservice:StudentService){}


  //初始化方法
ngOnInit(){
  this.testvalue='今天天气真好';
  this.numbervalue=58+76;
  this.studentvo=new StudentVo();
  this.student=new Student();
  this.s1=new Array();
  this.loadStudentList();


  //this.student.name="周艺"
  //this.student.sex="女"
  //this.student.stunum="201621447245"
  //this.student.birthday=new Date().getTime();
 //this.student.nativeplace="云南省东川区";

//  this.studentservice.getAnObject().then((data:any)=>{
//   this.student=data;
//   })
  }


  //保存方式
  add(){
    console.dir(this.studentvo);
    this.studentservice.addStudentInfo(this.studentvo)
    .then((data:any)=>{
    //请求事件完成后
    this.loadStudentList();
    
    })
    
    }
    
//载入student列表
loadStudentList(){
  this.studentservice.getStudentList().then((data:any)=>{
    this.s1=data;
  })
}

//获得单个student对象
getToUpdateStudent(id:string){
  this.studentservice.getSingleStudent(id).then((data:Student)=>{
    this.studentvo=new StudentVo();
    this.studentvo.studentid=data.studentid;
    this.studentvo.xh=data.stunum;
    this.studentvo.xm=data.name;;
  })
}

//删除student对象
deleteStudent(id:string){
  this.studentservice.deleteStudent(id).then((flag:boolean)=>{
    if(flag==true){
      this.loadStudentList();
  }
  else{
    alert("操作异常，请刷新后重试");
 }
})

}










}